{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入pyecharts库\n",
    "import pyecharts\n",
    "\n",
    "# 导入pandas库，用于处理数据\n",
    "import pandas as pd\n",
    "\n",
    "# numpy库，用于处理数据\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>房型</th>\n",
       "      <th>价格</th>\n",
       "      <th>小区</th>\n",
       "      <th>面积（㎡）</th>\n",
       "      <th>建造年份</th>\n",
       "      <th>户型</th>\n",
       "      <th>朝向</th>\n",
       "      <th>装修类型</th>\n",
       "      <th>楼层</th>\n",
       "      <th>区域</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>大华电梯两房/房型正气/开门南北通/房东诚意出售</td>\n",
       "      <td>76531</td>\n",
       "      <td>大华锦绣华城(十六街区)(公寓)</td>\n",
       "      <td>90.16</td>\n",
       "      <td>2010</td>\n",
       "      <td>2室2厅</td>\n",
       "      <td>南</td>\n",
       "      <td>简装</td>\n",
       "      <td>中楼层(共18层)</td>\n",
       "      <td>浦东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>非底楼 满五年唯一 税费少 婚房装修 楼称佳 户型方正</td>\n",
       "      <td>52290</td>\n",
       "      <td>芳雅苑</td>\n",
       "      <td>63.11</td>\n",
       "      <td>1995</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>南</td>\n",
       "      <td>精装</td>\n",
       "      <td>低楼层(共6层)</td>\n",
       "      <td>浦东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>满五唯一+7号线锦绣路+复式房+带阁楼+小区央位+精装</td>\n",
       "      <td>62878</td>\n",
       "      <td>锦博苑</td>\n",
       "      <td>79.52</td>\n",
       "      <td>2007</td>\n",
       "      <td>2室2厅</td>\n",
       "      <td>南</td>\n",
       "      <td>精装</td>\n",
       "      <td>高楼层(共6层)</td>\n",
       "      <td>浦东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>13号线陈春路地铁400米中间楼层诚意卖看房方便</td>\n",
       "      <td>45866</td>\n",
       "      <td>鹏海小区</td>\n",
       "      <td>71.95</td>\n",
       "      <td>1997</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>南</td>\n",
       "      <td>简装</td>\n",
       "      <td>中楼层(共6层)</td>\n",
       "      <td>浦东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>朝阳正气一房，采光好，坐看花园，户型方正，看房方便</td>\n",
       "      <td>83942</td>\n",
       "      <td>万邦都市花园</td>\n",
       "      <td>54.80</td>\n",
       "      <td>2004</td>\n",
       "      <td>1室1厅</td>\n",
       "      <td>南</td>\n",
       "      <td>简装</td>\n",
       "      <td>中楼层(共11层)</td>\n",
       "      <td>浦东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66010</th>\n",
       "      <td>富丽苑 2室2厅 275万</td>\n",
       "      <td>29743</td>\n",
       "      <td>富丽苑</td>\n",
       "      <td>92.46</td>\n",
       "      <td>2005</td>\n",
       "      <td>2室2厅</td>\n",
       "      <td>南</td>\n",
       "      <td>精装</td>\n",
       "      <td>中楼层(共6层)</td>\n",
       "      <td>宝山</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66011</th>\n",
       "      <td>房东自住精装修，集中式空调系统加地暖，带电梯。</td>\n",
       "      <td>35650</td>\n",
       "      <td>金辉兰湖美域</td>\n",
       "      <td>182.33</td>\n",
       "      <td>2013</td>\n",
       "      <td>4室2厅</td>\n",
       "      <td>南 北</td>\n",
       "      <td>精装</td>\n",
       "      <td>高楼层(共5层)</td>\n",
       "      <td>宝山</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66012</th>\n",
       "      <td>美兰湖颐景园 2室2厅 276万</td>\n",
       "      <td>32838</td>\n",
       "      <td>美兰湖颐景园</td>\n",
       "      <td>84.05</td>\n",
       "      <td>2007</td>\n",
       "      <td>2室2厅</td>\n",
       "      <td>南</td>\n",
       "      <td>精装</td>\n",
       "      <td>低楼层(共5层)</td>\n",
       "      <td>宝山</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66013</th>\n",
       "      <td>五楼低总价，两房朝南，满五唯一，格局好，配套齐全</td>\n",
       "      <td>26493</td>\n",
       "      <td>罗南二村</td>\n",
       "      <td>69.83</td>\n",
       "      <td>1996</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>南</td>\n",
       "      <td>简装</td>\n",
       "      <td>高楼层(共6层)</td>\n",
       "      <td>宝山</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66014</th>\n",
       "      <td>满五唯一，带电梯，精装修近地铁，户型方正楼层好</td>\n",
       "      <td>39983</td>\n",
       "      <td>美兰湖岭域</td>\n",
       "      <td>92.04</td>\n",
       "      <td>2010</td>\n",
       "      <td>2室2厅</td>\n",
       "      <td>南</td>\n",
       "      <td>精装</td>\n",
       "      <td>中楼层(共6层)</td>\n",
       "      <td>宝山</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>66015 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                房型     价格                 小区   面积（㎡）  建造年份  \\\n",
       "0         大华电梯两房/房型正气/开门南北通/房东诚意出售  76531  大华锦绣华城(十六街区)(公寓)    90.16  2010   \n",
       "1      非底楼 满五年唯一 税费少 婚房装修 楼称佳 户型方正  52290               芳雅苑    63.11  1995   \n",
       "2      满五唯一+7号线锦绣路+复式房+带阁楼+小区央位+精装  62878               锦博苑    79.52  2007   \n",
       "3         13号线陈春路地铁400米中间楼层诚意卖看房方便  45866              鹏海小区    71.95  1997   \n",
       "4        朝阳正气一房，采光好，坐看花园，户型方正，看房方便  83942            万邦都市花园    54.80  2004   \n",
       "...                            ...    ...                ...     ...   ...   \n",
       "66010                富丽苑 2室2厅 275万  29743               富丽苑    92.46  2005   \n",
       "66011      房东自住精装修，集中式空调系统加地暖，带电梯。  35650            金辉兰湖美域   182.33  2013   \n",
       "66012             美兰湖颐景园 2室2厅 276万  32838            美兰湖颐景园    84.05  2007   \n",
       "66013     五楼低总价，两房朝南，满五唯一，格局好，配套齐全  26493              罗南二村    69.83  1996   \n",
       "66014      满五唯一，带电梯，精装修近地铁，户型方正楼层好  39983             美兰湖岭域    92.04  2010   \n",
       "\n",
       "          户型     朝向  装修类型           楼层  区域  \n",
       "0      2室2厅      南    简装    中楼层(共18层)   浦东  \n",
       "1      2室1厅      南    精装     低楼层(共6层)   浦东  \n",
       "2      2室2厅      南    精装     高楼层(共6层)   浦东  \n",
       "3      2室1厅      南    简装     中楼层(共6层)   浦东  \n",
       "4      1室1厅      南    简装    中楼层(共11层)   浦东  \n",
       "...      ...    ...   ...          ...  ..  \n",
       "66010  2室2厅      南    精装     中楼层(共6层)   宝山  \n",
       "66011  4室2厅    南 北    精装     高楼层(共5层)   宝山  \n",
       "66012  2室2厅      南    精装     低楼层(共5层)   宝山  \n",
       "66013  2室1厅      南    简装     高楼层(共6层)   宝山  \n",
       "66014  2室2厅      南    精装     中楼层(共6层)   宝山  \n",
       "\n",
       "[66015 rows x 10 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取CSV格式文件，注意文件分隔要么用反斜杠/  要么用双斜\\\\\n",
    "f = open(\"Task_4_lianjia_sale.csv\", encoding=\"utf-8\")\n",
    "df = pd.read_csv(f)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### (1)根据任务4所统计的上海各个区的房均价数据，利用Pyecharts中的Map，以上海地图为背景作可视化展示图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>区域平均价格</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>区域</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>金山</th>\n",
       "      <td>19304.818824</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>奉贤</th>\n",
       "      <td>23662.131268</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>松江</th>\n",
       "      <td>36461.715479</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>嘉定</th>\n",
       "      <td>36587.687199</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>青浦</th>\n",
       "      <td>37078.860149</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          区域平均价格\n",
       "区域              \n",
       "金山  19304.818824\n",
       "奉贤  23662.131268\n",
       "松江  36461.715479\n",
       "嘉定  36587.687199\n",
       "青浦  37078.860149"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 利用groupby函数，以【区域】字段进行groupby，同时结合agg聚合函数统计各个区域平均房价，将统计所得平均房价命名为【区域平均价格】\n",
    "# df.groupby(\"被统计的列\")[\"选择一列做运算\"].agg({\"新列名\": \"mean\"}).sort_values(by=\"新列名\")\n",
    "df_avg = df.groupby(\"区域\")[\"价格\"].agg(区域平均价格=(\"mean\")).sort_values(by=\"区域平均价格\")\n",
    "df_avg.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', '上海':'https://assets.pyecharts.org/assets/maps/shanghai'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"f93939dd6c9047b68f0ab4813c61f1ce\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', '上海'], function(echarts) {\n",
       "                var chart_f93939dd6c9047b68f0ab4813c61f1ce = echarts.init(\n",
       "                    document.getElementById('f93939dd6c9047b68f0ab4813c61f1ce'), 'white', {renderer: 'canvas'});\n",
       "                var option_f93939dd6c9047b68f0ab4813c61f1ce = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"map\",\n",
       "            \"name\": \"\\u623f\\u4ef7\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"mapType\": \"\\u4e0a\\u6d77\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u91d1\\u5c71\\u533a\",\n",
       "                    \"value\": 19305.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5949\\u8d24\\u533a\",\n",
       "                    \"value\": 23662.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5609\\u5b9a\\u533a\",\n",
       "                    \"value\": 36462.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u677e\\u6c5f\\u533a\",\n",
       "                    \"value\": 36588.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9752\\u6d66\\u533a\",\n",
       "                    \"value\": 37079.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b9d\\u5c71\\u533a\",\n",
       "                    \"value\": 42578.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u95f5\\u884c\\u533a\",\n",
       "                    \"value\": 49081.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d66\\u4e1c\\u65b0\\u533a\",\n",
       "                    \"value\": 55413.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u666e\\u9640\\u533a\",\n",
       "                    \"value\": 57943.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6768\\u6d66\\u533a\",\n",
       "                    \"value\": 62727.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8679\\u53e3\\u533a\",\n",
       "                    \"value\": 66165.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u957f\\u5b81\\u533a\",\n",
       "                    \"value\": 72100.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9759\\u5b89\\u533a\",\n",
       "                    \"value\": 74305.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5f90\\u6c47\\u533a\",\n",
       "                    \"value\": 75396.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9ec4\\u6d66\\u533a\",\n",
       "                    \"value\": 95015.0\n",
       "                }\n",
       "            ],\n",
       "            \"roam\": true,\n",
       "            \"aspectScale\": 0.75,\n",
       "            \"nameProperty\": \"name\",\n",
       "            \"selectedMode\": false,\n",
       "            \"zoom\": 1,\n",
       "            \"mapValueCalculation\": \"sum\",\n",
       "            \"showLegendSymbol\": true,\n",
       "            \"emphasis\": {}\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u623f\\u4ef7\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u623f\\u4ef7\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u4e0a\\u6d77\\u5404\\u533a\\u623f\\u4ef7\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"continuous\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 100000,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"inverse\": false,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true,\n",
       "        \"itemWidth\": 20,\n",
       "        \"itemHeight\": 140,\n",
       "        \"borderWidth\": 0\n",
       "    }\n",
       "};\n",
       "                chart_f93939dd6c9047b68f0ab4813c61f1ce.setOption(option_f93939dd6c9047b68f0ab4813c61f1ce);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x7fa648efe7b8>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 导入pyecharts.charts中的Bar，作条形图\n",
    "from pyecharts.charts import Map\n",
    "# 导入配置项入口\n",
    "from pyecharts import options as opts\n",
    "\n",
    "# 定义区域名字\n",
    "districts = ['金山区', '奉贤区', '嘉定区', '松江区', '青浦区', '宝山区', '闵行区', '浦东新区', '普陀区', '杨浦区', '虹口区', '长宁区', '静安区', '徐汇区', '黄浦区']\n",
    "# 将avg_price数据值转成list 并将数值转成整数，作为纵坐标数据\n",
    "avg_price = np.round(df_avg[\"区域平均价格\"].values).tolist()\n",
    "\n",
    "# 构造地图对象\n",
    "m = Map()\n",
    "m.add(\"房价\", [list(z) for z in zip(districts, avg_price)], \"上海\")\n",
    "m.set_global_opts(\n",
    "# 设置标题\n",
    "    title_opts=opts.TitleOpts(title=\"上海各区房价\"),\n",
    "# 设置数值范围0-10万，is_piecewise标签值连续\n",
    "    visualmap_opts=opts.VisualMapOpts(max_=100000, is_piecewise=False),\n",
    ")\n",
    "\n",
    "# 直接在jupytr notebook中渲染\n",
    "m.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### (2)导入tushare数据包，提取A股基本数据信息，利用groupby函数统计每个省份的公司数量，并以中国地图为背景作相应图表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>symbol</th>\n",
       "      <th>name</th>\n",
       "      <th>area</th>\n",
       "      <th>industry</th>\n",
       "      <th>market</th>\n",
       "      <th>list_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>000001</td>\n",
       "      <td>平安银行</td>\n",
       "      <td>深圳</td>\n",
       "      <td>银行</td>\n",
       "      <td>主板</td>\n",
       "      <td>19910403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000002.SZ</td>\n",
       "      <td>000002</td>\n",
       "      <td>万科A</td>\n",
       "      <td>深圳</td>\n",
       "      <td>全国地产</td>\n",
       "      <td>主板</td>\n",
       "      <td>19910129</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000004.SZ</td>\n",
       "      <td>000004</td>\n",
       "      <td>国农科技</td>\n",
       "      <td>深圳</td>\n",
       "      <td>互联网</td>\n",
       "      <td>主板</td>\n",
       "      <td>19910114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>000005</td>\n",
       "      <td>世纪星源</td>\n",
       "      <td>深圳</td>\n",
       "      <td>环境保护</td>\n",
       "      <td>主板</td>\n",
       "      <td>19901210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000006.SZ</td>\n",
       "      <td>000006</td>\n",
       "      <td>深振业A</td>\n",
       "      <td>深圳</td>\n",
       "      <td>区域地产</td>\n",
       "      <td>主板</td>\n",
       "      <td>19920427</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>000007.SZ</td>\n",
       "      <td>000007</td>\n",
       "      <td>全新好</td>\n",
       "      <td>深圳</td>\n",
       "      <td>酒店餐饮</td>\n",
       "      <td>主板</td>\n",
       "      <td>19920413</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>000008.SZ</td>\n",
       "      <td>000008</td>\n",
       "      <td>神州高铁</td>\n",
       "      <td>北京</td>\n",
       "      <td>运输设备</td>\n",
       "      <td>主板</td>\n",
       "      <td>19920507</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>000009.SZ</td>\n",
       "      <td>000009</td>\n",
       "      <td>中国宝安</td>\n",
       "      <td>深圳</td>\n",
       "      <td>综合类</td>\n",
       "      <td>主板</td>\n",
       "      <td>19910625</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>000010.SZ</td>\n",
       "      <td>000010</td>\n",
       "      <td>美丽生态</td>\n",
       "      <td>深圳</td>\n",
       "      <td>建筑工程</td>\n",
       "      <td>主板</td>\n",
       "      <td>19951027</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>000011.SZ</td>\n",
       "      <td>000011</td>\n",
       "      <td>深物业A</td>\n",
       "      <td>深圳</td>\n",
       "      <td>区域地产</td>\n",
       "      <td>主板</td>\n",
       "      <td>19920330</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ts_code  symbol  name area industry market list_date\n",
       "0  000001.SZ  000001  平安银行   深圳       银行     主板  19910403\n",
       "1  000002.SZ  000002   万科A   深圳     全国地产     主板  19910129\n",
       "2  000004.SZ  000004  国农科技   深圳      互联网     主板  19910114\n",
       "3  000005.SZ  000005  世纪星源   深圳     环境保护     主板  19901210\n",
       "4  000006.SZ  000006  深振业A   深圳     区域地产     主板  19920427\n",
       "5  000007.SZ  000007   全新好   深圳     酒店餐饮     主板  19920413\n",
       "6  000008.SZ  000008  神州高铁   北京     运输设备     主板  19920507\n",
       "7  000009.SZ  000009  中国宝安   深圳      综合类     主板  19910625\n",
       "8  000010.SZ  000010  美丽生态   深圳     建筑工程     主板  19951027\n",
       "9  000011.SZ  000011  深物业A   深圳     区域地产     主板  19920330"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 导入tushare包，需要pip安装\n",
    "import tushare as ts\n",
    "# 第一次使用需设置 token，在 https://waditu.com/ 注册并填写个人资料后即可获得权限\n",
    "token = '你的token值'\n",
    "tushare.set_token(token)\n",
    "# 获取股票基本数据\n",
    "pro = ts.pro_api()\n",
    "df = pro.stock_basic()\n",
    "# 展示前10行数据\n",
    "df.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>公司数量</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>area</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>上海</th>\n",
       "      <td>333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>云南</th>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>内蒙</th>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>北京</th>\n",
       "      <td>378</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>吉林</th>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>四川</th>\n",
       "      <td>134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>天津</th>\n",
       "      <td>59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>宁夏</th>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>安徽</th>\n",
       "      <td>122</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>山东</th>\n",
       "      <td>223</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>山西</th>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>广东</th>\n",
       "      <td>339</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>广西</th>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>新疆</th>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>江苏</th>\n",
       "      <td>475</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>江西</th>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>河北</th>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>河南</th>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>浙江</th>\n",
       "      <td>502</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>海南</th>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>深圳</th>\n",
       "      <td>322</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>湖北</th>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>湖南</th>\n",
       "      <td>115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>甘肃</th>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>福建</th>\n",
       "      <td>148</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>西藏</th>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>贵州</th>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>辽宁</th>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>重庆</th>\n",
       "      <td>56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>陕西</th>\n",
       "      <td>59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>青海</th>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>黑龙江</th>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      公司数量\n",
       "area      \n",
       "上海     333\n",
       "云南      36\n",
       "内蒙      25\n",
       "北京     378\n",
       "吉林      42\n",
       "四川     134\n",
       "天津      59\n",
       "宁夏      14\n",
       "安徽     122\n",
       "山东     223\n",
       "山西      39\n",
       "广东     339\n",
       "广西      38\n",
       "新疆      58\n",
       "江苏     475\n",
       "江西      52\n",
       "河北      60\n",
       "河南      85\n",
       "浙江     502\n",
       "海南      32\n",
       "深圳     322\n",
       "湖北     110\n",
       "湖南     115\n",
       "甘肃      33\n",
       "福建     148\n",
       "西藏      20\n",
       "贵州      30\n",
       "辽宁      75\n",
       "重庆      56\n",
       "陕西      59\n",
       "青海      11\n",
       "黑龙江     37"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 利用groupby函数，以【area】字段进行groupby，同时结合agg聚合函数统计各个area公司数量，将统计所得数据命名为【公司数量】\n",
    "# df.groupby(\"被统计的列\")[\"选择一列做运算\"].agg({\"新列名\": \"count\"})\n",
    "df_num = df.groupby(\"area\")[\"name\"].agg(公司数量=(\"count\"))\n",
    "df_num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'china':'https://assets.pyecharts.org/assets/maps/china'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"6c35717cacf0473cb2afe73dd195fd21\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'china'], function(echarts) {\n",
       "                var chart_6c35717cacf0473cb2afe73dd195fd21 = echarts.init(\n",
       "                    document.getElementById('6c35717cacf0473cb2afe73dd195fd21'), 'white', {renderer: 'canvas'});\n",
       "                var option_6c35717cacf0473cb2afe73dd195fd21 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"map\",\n",
       "            \"name\": \"\\u5546\\u5bb6A\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"mapType\": \"china\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u4e0a\\u6d77\",\n",
       "                    \"value\": 333\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e91\\u5357\",\n",
       "                    \"value\": 36\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5185\\u8499\",\n",
       "                    \"value\": 25\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5317\\u4eac\",\n",
       "                    \"value\": 378\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5409\\u6797\",\n",
       "                    \"value\": 42\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u56db\\u5ddd\",\n",
       "                    \"value\": 134\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5929\\u6d25\",\n",
       "                    \"value\": 59\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b81\\u590f\",\n",
       "                    \"value\": 14\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b89\\u5fbd\",\n",
       "                    \"value\": 122\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u4e1c\",\n",
       "                    \"value\": 223\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u897f\",\n",
       "                    \"value\": 39\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u4e1c\",\n",
       "                    \"value\": 339\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u897f\",\n",
       "                    \"value\": 38\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u65b0\\u7586\",\n",
       "                    \"value\": 58\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u82cf\",\n",
       "                    \"value\": 475\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u897f\",\n",
       "                    \"value\": 52\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5317\",\n",
       "                    \"value\": 60\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5357\",\n",
       "                    \"value\": 85\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d59\\u6c5f\",\n",
       "                    \"value\": 502\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d77\\u5357\",\n",
       "                    \"value\": 32\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6df1\\u5733\",\n",
       "                    \"value\": 322\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5317\",\n",
       "                    \"value\": 110\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5357\",\n",
       "                    \"value\": 115\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u7518\\u8083\",\n",
       "                    \"value\": 33\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u798f\\u5efa\",\n",
       "                    \"value\": 148\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u897f\\u85cf\",\n",
       "                    \"value\": 20\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8d35\\u5dde\",\n",
       "                    \"value\": 30\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8fbd\\u5b81\",\n",
       "                    \"value\": 75\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u91cd\\u5e86\",\n",
       "                    \"value\": 56\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9655\\u897f\",\n",
       "                    \"value\": 59\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9752\\u6d77\",\n",
       "                    \"value\": 11\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9ed1\\u9f99\\u6c5f\",\n",
       "                    \"value\": 37\n",
       "                }\n",
       "            ],\n",
       "            \"roam\": true,\n",
       "            \"aspectScale\": 0.75,\n",
       "            \"nameProperty\": \"name\",\n",
       "            \"selectedMode\": false,\n",
       "            \"zoom\": 1,\n",
       "            \"mapValueCalculation\": \"sum\",\n",
       "            \"showLegendSymbol\": true,\n",
       "            \"emphasis\": {}\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u5546\\u5bb6A\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u5546\\u5bb6A\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u516c\\u53f8\\u5730\\u533a\\u5206\\u5e03\\u56fe\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"piecewise\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 500,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"inverse\": false,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true,\n",
       "        \"itemWidth\": 20,\n",
       "        \"itemHeight\": 14,\n",
       "        \"borderWidth\": 0\n",
       "    }\n",
       "};\n",
       "                chart_6c35717cacf0473cb2afe73dd195fd21.setOption(option_6c35717cacf0473cb2afe73dd195fd21);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x7fa64b9a8c88>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 导入pyecharts.charts中的Bar，作地图\n",
    "from pyecharts.charts import Map\n",
    "# 导入配置项入口\n",
    "from pyecharts import options as opts\n",
    "\n",
    "# 将df_num的索引即【area】提取出来，并转换成list\n",
    "df_province = df_num.index.values.tolist()\n",
    "# 将df_num的【公司数量】一列的数据值提取出来，并转换成list\n",
    "df_company_num = df_num[\"公司数量\"].values.tolist()\n",
    "\n",
    "# 构造地图对象\n",
    "m = Map()\n",
    "# 中国地图\n",
    "m.add(\"商家A\", [list(z) for z in zip(df_province, df_company_num)], \"china\")\n",
    "m.set_global_opts(\n",
    "# 设置标题\n",
    "    title_opts=opts.TitleOpts(title=\"公司地区分布图\"),\n",
    "# 设置数值范围0-500，is_piecewise标签值连续或者分段\n",
    "    visualmap_opts=opts.VisualMapOpts(max_=500, is_piecewise=True),\n",
    ")\n",
    "\n",
    "# 直接在jupytr notebook中渲染\n",
    "m.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'china':'https://assets.pyecharts.org/assets/maps/china'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"dfe410af81004e8b8b3f3dab6b57af7f\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'china'], function(echarts) {\n",
       "                var chart_dfe410af81004e8b8b3f3dab6b57af7f = echarts.init(\n",
       "                    document.getElementById('dfe410af81004e8b8b3f3dab6b57af7f'), 'white', {renderer: 'canvas'});\n",
       "                var option_dfe410af81004e8b8b3f3dab6b57af7f = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"map\",\n",
       "            \"name\": \"2019\\u5e74\\u5168\\u56fd\\u5404\\u7701\\u82f9\\u679c\\u4ef7\\u683c\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"mapType\": \"china\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u5317\\u4eac\",\n",
       "                    \"value\": 10.84\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5929\\u6d25\",\n",
       "                    \"value\": 8.65\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5317\",\n",
       "                    \"value\": 18.06\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u897f\",\n",
       "                    \"value\": 8.9\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5185\\u8499\\u53e4\",\n",
       "                    \"value\": 5.04\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8fbd\\u5b81\",\n",
       "                    \"value\": 29.2\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5409\\u6797\",\n",
       "                    \"value\": 8.98\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9ed1\\u9f99\\u6c5f\",\n",
       "                    \"value\": 17.8\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e0a\\u6d77\",\n",
       "                    \"value\": 27.81\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u82cf\",\n",
       "                    \"value\": 24.24\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d59\\u6c5f\",\n",
       "                    \"value\": 12.72\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b89\\u5fbd\",\n",
       "                    \"value\": 11.1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u798f\\u5efa\",\n",
       "                    \"value\": 6.3\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u897f\",\n",
       "                    \"value\": 7.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u4e1c\",\n",
       "                    \"value\": 22.45\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5357\",\n",
       "                    \"value\": 16.92\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5317\",\n",
       "                    \"value\": 11.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5357\",\n",
       "                    \"value\": 14.99\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u4e1c\",\n",
       "                    \"value\": 18.85\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u897f\",\n",
       "                    \"value\": 5.85\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d77\\u5357\",\n",
       "                    \"value\": 1.4\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u91cd\\u5e86\",\n",
       "                    \"value\": 7.32\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u56db\\u5ddd\",\n",
       "                    \"value\": 14.61\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8d35\\u5dde\",\n",
       "                    \"value\": 4.62\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e91\\u5357\",\n",
       "                    \"value\": 6.05\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9655\\u897f\",\n",
       "                    \"value\": 8.07\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u7518\\u8083\",\n",
       "                    \"value\": 6.73\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9752\\u6d77\",\n",
       "                    \"value\": 15.54\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b81\\u590f\",\n",
       "                    \"value\": 13.0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u65b0\\u7586\",\n",
       "                    \"value\": 39.07\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u897f\\u85cf\",\n",
       "                    \"value\": 25.61\n",
       "                }\n",
       "            ],\n",
       "            \"roam\": true,\n",
       "            \"aspectScale\": 0.75,\n",
       "            \"nameProperty\": \"name\",\n",
       "            \"selectedMode\": false,\n",
       "            \"zoom\": 1,\n",
       "            \"mapValueCalculation\": \"sum\",\n",
       "            \"showLegendSymbol\": true,\n",
       "            \"emphasis\": {}\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"2019\\u5e74\\u5168\\u56fd\\u5404\\u7701\\u82f9\\u679c\\u4ef7\\u683c\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"2019\\u5e74\\u5168\\u56fd\\u5404\\u7701\\u82f9\\u679c\\u4ef7\\u683c\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"2019\\u5e74\\u5168\\u56fd\\u5404\\u7701\\u82f9\\u679c\\u4ef7\\u683c\\u8868\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"continuous\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 50,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"inverse\": false,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true,\n",
       "        \"itemWidth\": 20,\n",
       "        \"itemHeight\": 140,\n",
       "        \"borderWidth\": 0\n",
       "    }\n",
       "};\n",
       "                chart_dfe410af81004e8b8b3f3dab6b57af7f.setOption(option_dfe410af81004e8b8b3f3dab6b57af7f);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x7fa646323fd0>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts.charts import Map,Geo\n",
    "from pyecharts import options as opts\n",
    "#将数据处理成列表\n",
    "locate = ['北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','上海','江苏','浙江','安徽','福建','江西','山东','河南','湖北','湖南','广东','广西','海南','重庆','四川','贵州','云南','陕西','甘肃','青海','宁夏','新疆','西藏']\n",
    "app_price = [10.84,8.65,18.06,8.90,5.04,29.20,8.98,17.80,27.81,24.24,12.72,11.10,6.30,7.00,22.45,16.92,11.00,14.99,18.85,5.85,1.40,7.32,14.61,4.62,6.05,8.07,6.73,15.54,13.00,39.07,25.61,21.3]\n",
    "list1 = [[locate[i],app_price[i]] for i in range(len(locate))]\n",
    "map_1 = Map()\n",
    "map_1.set_global_opts(\n",
    "    title_opts=opts.TitleOpts(title=\"2019年全国各省苹果价格表\"),\n",
    "    visualmap_opts=opts.VisualMapOpts(max_=50)  #最大数据范围\n",
    "    )\n",
    "map_1.add(\"2019年全国各省苹果价格\", list1, maptype=\"china\")\n",
    "map_1.render_notebook()\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
